'''oto/publisher.py

This module contains the Publisher class.
'''

__authors__ = ['Ryan Rousseau <ryan.rousseau@gmail.com>']
__license__ = '''Oranges to Oranges
Copyright (C) 2006  Ryan Rousseau

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''


import Pyro.EventService.Clients

from constants import *

__all__ = ['Publisher']

## Publisher ##

class Publisher(Pyro.EventService.Clients.Publisher):
    '''Publisher(name)

Pyro event publisher for Oranges to Oranges.
name is the name used by the publisher, usually it is the name of the 
associated sequence.
'''

    def __init__(self, name):
        Pyro.EventService.Clients.Publisher.__init__(self)
        self.name = name

    def publish_event(self, game, event, message):
        '''publish_event(game, event, message)
'''
        # print 'PUBLISHING EVENT %s' % event
        channel = '%s.%s' % (EVENT_CHANNEL, self.name)
        self.publish(channel, (game, event, message))
